FileChooserWidget: Fix leaks in .get_subtitle()
authorDaniel Boles <dboles@src.gnome.org>
Tue, 13 Mar 2018 00:19:51 +0000 (00:19 +0000)
committerDaniel Boles <dboles@src.gnome.org>
Tue, 13 Mar 2018 00:20:17 +0000 (00:20 +0000)
Now that subtitle's default value "Searching" for OPERATION_MODE_SEARCH
is duplicated as it should be, we cannot reassign other strings to it
anymore, as that resulted in the original dupe of "Searching" leaking.

Fix this by only assigning the dup'd "Searching" after trying to get
more specific values, not before. We therefore need to set it to NULL
during its declaration, and that means we needn't in the final else.

gtk/gtkfilechooserwidget.c

index e94de516bd9081d9341aaf1b5a364627565a4f79..b23f1dbf0088143ab98813b79016d2f422abf0d7 100644 (file)
@@ -3192,14 +3192,12 @@ static gchar *
 gtk_file_chooser_widget_get_subtitle (GtkFileChooserWidget *impl)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
-  gchar *subtitle;
+  gchar *subtitle = NULL;
 
   if (priv->operation_mode == OPERATION_MODE_SEARCH)
     {
       gchar *location;
 
-      subtitle = g_strdup (_("Searching"));
-
       location = gtk_places_sidebar_get_location_title (GTK_PLACES_SIDEBAR (priv->places_sidebar));
       if (location)
         {
@@ -3221,6 +3219,9 @@ gtk_file_chooser_widget_get_subtitle (GtkFileChooserWidget *impl)
               g_object_unref (info);
             }
         }
+
+      if (subtitle == NULL)
+        subtitle = g_strdup (_("Searching"));
     }
   else if (priv->operation_mode == OPERATION_MODE_ENTER_LOCATION ||
            (priv->operation_mode == OPERATION_MODE_BROWSE &&
@@ -3231,10 +3232,6 @@ gtk_file_chooser_widget_get_subtitle (GtkFileChooserWidget *impl)
       else
         subtitle = g_strdup (_("Enter location or URL"));
     }
-  else
-    {
-      subtitle = NULL;
-    }
 
   return subtitle;
 }